﻿<cfscript>
/** 
* @hint "acadmicBase - Campus"
*/ 

component 
	extends="MachII.framework.Listener" 
	displayname="acadmicManager.listeners.senate.campusListener" 
	output=false 
	depends="sequenceCampus"
	{
		
	/**
	* @hint "Configures this listener as part of the Mach-II framework"
	*/
	public void function configure() output=false {} 
	
	/**
	* @hint "删除校区信息"
	* 
	* @event "MachII Event Object"
	*/
	public void function deleteCampus ( required MachII.framework.Event event ) output=false {
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			var sql = "	DELETE FROM
							t_campus c
						WHERE 
							c.campus_id = :campusId ";

			var queryObj = new Query(datasource = application.dnsMaster);
			queryObj.addParam(name = "campusId", value = event.getArg("CampusID"), cfsqltype = "cf_sql_char");
			queryObj.execute(sql = sql);
		}
	}
	
	/**
	* @hint "更新校区信息"
	* 
	* @event "MachII Event Object"
	*/
	public void function updateCampus( required MachII.framework.Event event ) output=false {
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			var sql = "	UPDATE
							t_campus c
						SET
							c.campus_name = :campusName ,
							c.campus_address = :address ,
							c.campus_zipcode = :zipcode 
						WHERE
							c.campus_id = :campusId ";

			var queryObj = new Query(datasource = application.dnsMaster);
			queryObj.addParam(name = "campusId", value = event.getArg("CampusID"), cfsqltype = "cf_sql_char");
			queryObj.addParam(name = "campusName", value = event.getArg("CampusName"), cfsqltype = "cf_sql_varchar");
			queryObj.addParam(name = "address", value = event.getArg("Address"), cfsqltype = "cf_sql_varchar");
			queryObj.addParam(name = "zipcode", value = event.getArg("ZipCode"), cfsqltype = "cf_sql_char");
			queryObj.execute(sql = sql);
		}
		
		event.setArg("CID", event.getArg("CampusID"));
		event.setArg("TabID", "labBaseInfo");
	}
	
	/**
	* @hint "创建校区信息"
	* 
	* @event "MachII Event Object"
	*/
	public void function createCampus( required MachII.framework.Event event ) output=false {
		var sequenceCampus = getsequenceCampus();
		var campus = "";
		var passArg = structNew();
		
		/* Every SQL operation is TRANSACATION*/
		transaction {

			var sql = "	INSERT INTO t_campus(
							campus_id,
							campus_name,
							campus_address,
							campus_zipcode
						)VALUES(
							:campusId ,
							:campusName ,
							:address ,
							:zipcode 
						)";
			var queryObj = new Query(datasource = application.dnsMaster);
			queryObj.addParam(name = "campusId", value = sequenceCampus.getID(), cfsqltype = "cf_sql_char");
			queryObj.addParam(name = "campusName", value = event.getArg("CampusName"), cfsqltype = "cf_sql_varchar");
			queryObj.addParam(name = "address", value = event.getArg("Address"), cfsqltype = "cf_sql_varchar");
			queryObj.addParam(name = "zipcode", value = event.getArg("ZipCode"), cfsqltype = "cf_sql_char");
			queryObj.execute(sql = sql);
		}
		
	}

}

</cfscript>